package chp09;

import java.util.Scanner;

public class Test6 {

    static Scanner input = new Scanner(System.in);

    /*
    * 学号    姓名
    * 101   jack
    * 103   tom
    * 109   mike
    *
    * */

    static int[] ids = new int[50];
    static String[] names = new String[50];

    public static void init(){
        /*
        * 101   jack
         * 103   tom
         * 109   mike*/
        ids[0] = 101;
        names[0] = "jack";
        ids[1] = 103;
        names[1] = "tom";
        ids[2] = 109;
        names[2] = "mike";
        System.out.println("初始化学生信息成功..");
    }


    public static void loginMenu(){
        System.out.println("欢迎使用学生管理系统");
        System.out.println("1.进入系统");
        System.out.println("2.退出");
        System.out.print("请选择:");
        int choose = input.nextInt();
        if(choose == 1){
            mainMenu();
        }else{
            System.out.println("再见");
        }
    }

    public static void mainMenu(){
        while (true) {
            System.out.println("\n成功进入系统");
            System.out.println("1.新增学生");
            System.out.println("2.修改学生");
            System.out.println("3.查询学生");
            System.out.println("4.删除学生");
            System.out.print("请选择:");
            String choose = input.next();
            if (choose.equals("1")) {
                addStudent();
            } else if (choose.equals("2")) {

            } else if (choose.equals("3")) {
                showAllStudent();
            } else if (choose.equals("4")) {

            }
        }
    }

    public static void showAllStudent(){
        System.out.println("学号\t姓名");
        for (int i = 0; i < ids.length; i++) {
            if(ids[i] == 0){
                break;
            }
            System.out.println(ids[i]+"\t\t"+names[i]);
        }
    }

    public static void addStudent(){
        System.out.print("请输入学号:");
        int id = input.nextInt();
        System.out.print("请输入姓名:");
        String name = input.next();
        for (int i = 0; i < ids.length; i++) {
            if(ids[i] == 0){
                ids[i] = id;
                names[i] = name;
                System.out.println("新增学生成功");
                break;
            }
        }
    }

    public static void main(String[] args) {
        init();
        loginMenu();
    }
}
